﻿using BXH.Movie.Bll;
using BXH.Movie.Common;
using CCWin;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BXH.Movie.FrmAdmin
{
    public partial class FrmChangePassword : CCWin.CCSkinMain
    {
        public FrmChangePassword()
        {
            InitializeComponent();
        }

        private UserInfoService userInfoService = new UserInfoService();
        private void FrmChangePassword_Load(object sender, EventArgs e)
        {
          
            //Program.LoginUser

            // userInfoService.Update();
        }

        private void btnChangePassword_Click(object sender, EventArgs e)
        {
            if (txtPassword.Text.Length <= 0 || txtRpassword.Text.Length <= 0 || txtOldPassword.Text.Length <= 0)
            {
                MessageBoxEx.Show("请填写表单数据");
                return;
            }

            if (txtPassword.Text != txtRpassword.Text)
            {
                MessageBoxEx.Show("两次密码不一致");
                return;
            }
            var oldPassword = txtOldPassword.Text;
            var passwordEncrypt = Encrypt.MD5Encrypt16(oldPassword);//加密
            if (userInfoService.Login(Program.LoginUser.UserCode, passwordEncrypt) != null)
            {
                Program.LoginUser.Password = Encrypt.MD5Encrypt16(txtPassword.Text);
                if (userInfoService.Update(Program.LoginUser))
                {
                    MessageBoxEx.Show("修改密码成功");
                    this.Close();
                }
            }

        }
    }
}
